import React, { Component } from 'react'
import axios from 'axios'
export default class search extends Component {
  searchName = () => {
    const { inputElment: { value: searchKey } } = this
    this.props.changeState('isLoading', true)
    axios.get(`http://localhost:3000/api/search?q=${searchKey}`)
      .then(
        res => {
          this.props.changeState('users', res.data)
          this.props.changeState('isLoading', false)
        },
        err => {
          console.log(err)
        }
      )
  }
  render() {
    return (
      <div className="search">
        <input ref={c => this.inputElment = c} type="text" />&nbsp;
        <button onClick={this.searchName}>search</button>
      </div>
    )
  }
}
